package com.sg.business.commons.field.value;

import java.util.List;

import com.sg.business.model.ManagermentCategory;
import com.sg.widgets.Widgets;
import com.sg.widgets.part.editor.fields.value.IFieldDefaultValue;
import com.sg.widgets.registry.config.Option;

public class OverTimeDefault implements IFieldDefaultValue {

	public OverTimeDefault() {
	}

	@Override
	public Object getDefaultValue(Object data, String key) {
		List<Option> subOption = getOptions();
		Option childOption = subOption.get(0);
		String value = childOption.getValue().toString();
		if (data instanceof ManagermentCategory) {
			ManagermentCategory managermentCategory = (ManagermentCategory) data;
			managermentCategory.setValue(key, value);
		}
		return value;
	}

	private List<Option> getOptions() {
		Option option = (Option) Widgets.getOptionRegistry().getConfigurator(
				"category.overtimemargin");//$NON-NLS-1$
		List<Option> subOption = option.getSubOption();
		return subOption;
	}
}
